package daos;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Conexao {

	private Connection con;
	
	public void gerarConexao(){
		
		synchronized(this){

			try{
				
				Class.forName("com.mysql.jdbc.Driver");
				con = DriverManager.getConnection("jdbc:mysql://localhost:3306/associador_informacoes","root","sarai");

				
			}catch(SQLException a){
				a.printStackTrace();
			}
			catch(ClassNotFoundException a){
				a.printStackTrace();
			}
			
		}
		
	}
	
	public Connection getConexao(){

		synchronized(this){

			if(con == null){
				gerarConexao();
			}
			
			return con;
			
		}
	}
	
	public void shutDown() throws SQLException {

		synchronized(this){
			if(con != null){
				con.close();
			}
		}
	}
}
